package interfaz2;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import dustconf.DustConf;

/**
 * The view of the DustConf module following the MVC design pattern.
 * 
 * @author ole
 */
/** TODO: This class is not really implemented yet. Do it. **/
public class ConfigurationComposite extends DustComposite {
	/*
	 * Private classes.
	 */

	/**
	 * Class that handles the selection of the "Load" button.
	 */
	private class LoadButtonListener extends SelectionAdapter {
		@Override
		public void widgetSelected(SelectionEvent event) {
			;
		}
	}

	/**
	 * Class that handles the selection of the "Save" button.
	 */
	private class SaveButtonListener extends SelectionAdapter {
		@Override
		public void widgetSelected(SelectionEvent event) {
			;
		}
	}

	/**
	 * Class constructor.
	 * 
	 * @param parent:
	 * 		The parent Composite of this Composite.
	 */
	public ConfigurationComposite(Composite parent) {
		super(parent, SWT.NONE);
		
		// The configuration Composite has at the top buttons to operate, and
		// at the bottom a Composite with the possible variables edition.
		GridData grid;
		Label label;
		Text entry_text;
		Button button;
		Composite buttons_comp, config_comp;
		GridLayout gridlayout;
		
		this.setLayout(new GridLayout());
		grid = new GridData(GridData.FILL, GridData.FILL, true, true);
		this.setLayoutData(grid);
		
		// The buttons Composite.
		buttons_comp = new Composite(this, SWT.NONE);
		buttons_comp.setLayout(new FillLayout());
		
		// A button to save this configuration.
		button = new Button(buttons_comp, SWT.NONE);
		button.setText("Save configuration");
		button.addSelectionListener(new SaveButtonListener());
		
		// A button to load a configuration from a file.
		button = new Button(buttons_comp, SWT.NONE);
		button.setText("Load configuration");
		button.addSelectionListener(new LoadButtonListener());
		
		// The bottom Composite.
		config_comp = new Composite(this, SWT.NONE);
		gridlayout = new GridLayout();
		gridlayout.numColumns = 2;
		config_comp.setLayout(gridlayout);
		
		for (String varname: DustConf.varnames) {
			label = new Label(config_comp, SWT.NONE);
			label.setText(varname + ":");
			
			entry_text = new Text(config_comp, SWT.BORDER);
			// Just to avoid the "never read" warning.
			entry_text.getClass();
		}
	}
}
